###############################################################################   
#### Replication Materials                                                 #### 
#### Kim, Nakka, Gopal, Desmrais, Mancinelli, Harden, Ko, Boehmke. 2021.   ####
#### Attention to the COVID-19 pandemic on Twitter:                        ####
#### Partisan differences among U.S. state legislators                     ####
#### Legislative Studies Quarterly                                         ####
###############################################################################  


###############################################################################
################################### Set Up ####################################
###############################################################################

# packages -------------------------

lapply(c("Hmisc", "arm", "readr", "tidyverse", "lme4", "stargazer", "texreg",
         "xtable", "dummies","effects", "ggthemes","caret", "ggeffects", 'plm', 
         "lmtest","scales","ggrepel","sandwich","reshape2", "plyr"), 
       require, 
       character.only = TRUE)

# read respective data sets -------------------------

# set data path
data_path <- '/Users/taegyoon/Google Drive/spap_state/spap_state_attention/data/' 

# read data
general <- read_csv(paste0(data_path, "spap_state_attention_supplementary_general.csv"))
pandemic_agg_state <- read_csv(paste0(data_path, "spap_state_attention_supplementary_pandemic_state.csv"))
pandemic_agg_national <- read_csv(paste0(data_path, "spap_state_attention_supplementary_pandemic_national.csv"))
policy_grouped <- read_csv(paste0(data_path, "spap_state_attention_supplementary_policy.csv"))




###############################################################################
############################# SI Tables 1, 3, 4 ###############################
###############################################################################

# Table S1  -------------------------

t_party <- table(general[which(general$week == 14), ]$party_new)
round(prop.table(t_party), 4)

t_chamber <- table(general[which(general$week == 14), ]$chamber)
round(prop.table(t_chamber), 4)

df_gender <- read_csv(paste0(data_path, 
                              "spap_state_attention_supplementary_gender.csv")) 
t_gender <- table(df_gender$gender_predicted_new)
round(prop.table(t_gender), 4)

# Table S3 -------------------------

table(general[which(general$'week' == 14), ]$republican)
table(general[which(general$'week' == 14), ]$major_cham)

# Table S4 -------------------------

summary(general$covid_relevant_1_log)

state_ind <- c('state_case', 
               'state_case_pop', 
               'state_death', 
               'state_death_pop')
summary(pandemic_agg_state[which(pandemic_agg_state$week>=14),][state_ind])

national_ind <- c('national_case', 
                'national_case_pop',
                'national_death',
                'national_death_pop')
summary(pandemic_agg_national[which(pandemic_agg_national$week>=14),][national_ind])

summary(policy_grouped[which(policy_grouped$week>=14),]$state_covid_policy)

summary(head(general, 
             length(unique(regression_final$user.screen_name)))$np_score)